package com.helper.easyHelper.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author 狠穿
 * @version 1.0.0
 * @date 2023/1/29
 */
public class DBUtils {

    private static String driver = "com.mysql.jdbc.Driver";
    private static String url = "jdbc:mysql://localhost:3306/device?characterEncoding=UTF-8&useSSL=false";
    private static String username = "root";
    private static String password = "root";
    private static Connection conn ;

    public static Connection getConnection(){
        if( conn != null ){
            return conn;
        }
        //注册驱动
        try {
            Class.forName(driver);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        //获取连接
        try {
            conn = DriverManager.getConnection(url, username, password);
            return conn;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

}
